
import axios from 'axios';
function httpHeaders() {
    return {
        'Access-Control-Allow-Origin': axios.defaults.baseURL,
        'DeviceType': 1,
        'UserId':  localStorage.getItem("UserId")
    };
}

export default {
    async POST(url, parameters, responseType) {
        try {
            const res = await axios.post(url, parameters, {
                headers: httpHeaders()
            });
            if (responseType === "blob") {
                return res;
            } else {
                return successHandle(res);
            }
        } catch (error) {
            return errorHandle(error);
        }
    },
    async GET(url) {
        try {
            const res = await axios.get(url, {
                headers: httpHeaders()
            });
            return successHandle(res);
        } catch (error) {
            return errorHandle(error);
        }
    }

}


function successHandle(res) {
    const data = res.data;
    return data;
}

function errorHandle(error) {
    let meesage = '后台异常';
    if (error && error.request) {
        const status = error.request.status;
        if (status == 0) {
            meesage = '未请求到网络连接';
        }
    }
    return {
        Success: false,
        Message: meesage
    }
}